<template>
  <div class="top-bar">
    <div class="color-legend"></div>
    <div class="location" @click="initCamera">
      <img src="../images/pos.png" alt="" />
    </div>
    <div class="zoom">
      <div :class="['state-switch', isLaunch ? 'state-active' : '']">
        <div
          :class="['state', isState == 'wx' ? 'stateA' : '']"
          @click="handleChangeMapStyle('wx')"
        >
          <img src="" alt="" />
        </div>
        <div
          :class="['state', isState == 'xz' ? 'stateA' : '']"
          @click="handleChangeMapStyle('xz')"
        >
          <img src="" alt="" />
        </div>
        <img v-if="!isLaunch" @click="launch" src="../images/open.png" alt="" />
        <img v-if="isLaunch" @click="launch" src="../images/put.png" alt="" />
      </div>
      <div class="zoom-box">
        <div @click="enlarge">
          <img src="../images/jia.png" alt="" />
        </div>
        <div class="line"></div>
        <div @click="narrow">
          <img src="../images/jian.png" alt="" />
        </div>
      </div>
    </div>
    <div class="position-wrap">
      <div v-if="componentVisible === 'zhjc'" class="position">
        <p>经度：{{ lng }}</p>
        <p>纬度：{{ lat }}</p>
      </div>
      <div class="size">500英里</div>
    </div>
  </div>
</template>

<script setup lang="ts">
import * as L from 'leaflet'
import { createTileLayer } from '@quickearth/leaflet'
import { predefinedImageTiles } from '@quickearth/core'
import { useMonitoringStore } from '@/pages/integrated-monitoring/store/store'
import yulinSideGeojson from '@/assets/data/yulin-side.json'
import yulinGeojson from '@/assets/data/yulin.json'
const monitoringStore = useMonitoringStore()
const lng = ref(0)
const lat = ref(0)
useEventBus('currentMapPositionLatLng').on((lngData, latData) => {
  lng.value = lngData
  lat.value = latData
})

const componentVisible = inject('componentVisible')
const tabsList = [
  {
    label: '综合监测',
    path: 'zhjc'
  }
]
//放大
const enlarge = () => {
  useEventBus('handleEnlarge').emit()
}
//缩小
const narrow = () => {
  useEventBus('handleNarrow').emit()
}
//展开
const isLaunch = ref(false)
const launch = () => {
  isLaunch.value = !isLaunch.value
}
const isState = ref('wx')
// 图层处理
const handleChangeMapStyle = val => {
  isState.value = val
  switch (val) {
    case 'xz':
      useEventBus('handleRemoveLayer').emit('tdtSatellite')
      useEventBus('handleAddLayer').emit(
        createTileLayer(predefinedImageTiles.tdtNormal),
        'tdtNormal'
      )
      break
    case 'wx':
      useEventBus('handleRemoveLayer').emit('tdtNormal')
      useEventBus('handleAddLayer').emit(
        createTileLayer(predefinedImageTiles.tdtSatellite),
        'tdtSatellite'
      )
      break
  }
}
const initCamera = () => {
  useEventBus('handleInitCameraPosition').emit()
  useEventBus('handleRemoveLayer').emit('taiyuanqxWhite')
  useEventBus('handleRemoveLayer').emit('taiyuanshiWhite')
  useEventBus('handleRemoveLayer').emit('yulinWhite')
  useEventBus('handleRemoveLayer').emit('yulinSideWhite')
  monitoringStore.componentsVisible.labels = '全部'
  useEventBus('handleInitLayer').emit(yulinGeojson, 'yulinWhite')
}
const handleChangeTab = val => {
  componentVisible.value = val
}
</script>

<style scoped lang="scss">
.top-bar {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 20%;
  height: 600px;
  background-color: transparent;
  z-index: 1200;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  box-sizing: border-box;
  .color-legend {
    width: 21px;
    height: 400px;
    background: linear-gradient(
      180deg,
      #acefa4 0%,
      #4bc63f 25%,
      #3bd2ff 43%,
      #0401e0 62%,
      #ed24f4 78%,
      #6d1341 100%
    );
    border-radius: 19px 19px 19px 19px;
    position: absolute;
    right: 21px;
    bottom: 157px;
  }
  .location {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    position: absolute;
    right: 17px;
    bottom: 119px;
    background: rgba(0, 17, 46, 0.66);
    box-shadow: 0px 0px 10px 1px rgba(0, 0, 0, 0.47);
    border: 1px solid rgba(255, 255, 255, 0.23);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    img {
      width: 16px;
      height: 16px;
    }
  }
  .zoom {
    width: 100%;
    min-height: 60px;
    display: flex;
    justify-content: flex-end;
    align-items: end;
    position: absolute;
    right: 17px;
    bottom: 50px;
    .zoom-box {
      width: 30px;
      height: 60px;
      background: rgba(0, 17, 46, 0.66);
      box-shadow: 0px 0px 10px 1px rgba(0, 0, 0, 0.47);
      // border-radius: 15px 15px 15px 15px;
      border: 1px solid rgba(255, 255, 255, 0.23);
      padding: 8px 5px;
      box-sizing: border-box;
      div:first-child {
        width: 100%;
        height: 49%;
        display: flex;
        justify-content: center;
        align-items: start;
        cursor: pointer;
        img {
          width: 14px;
          height: 14px;
        }
      }
      div:last-child {
        width: 100%;
        height: 40%;
        display: flex;
        justify-content: center;
        align-items: end;
        cursor: pointer;
        img {
          width: 14px;
          height: 1.75px;
        }
      }

      .line {
        width: 100%;
        height: 1px;
        background-color: #fff;
        opacity: 0.18;
      }
    }
    .state-switch {
      width: 151px;
      height: 60px;
      background: rgba(10, 146, 253, 0.09);
      box-shadow: 0px 0px 8px 1px #0a92fd;
      border-radius: 6px 6px 6px 6px;
      border: 1px solid #0a92fd;
      margin-right: 18px;
      padding: 9px 5px;
      box-sizing: border-box;
      display: flex;
      align-items: center;
      justify-content: space-around;
      .state {
        width: 44px;
        height: 44px;
        background: #ffffff;
        border-radius: 22px 22px 22px 22px;
        border: 1px solid #707070;
        margin-right: 10px;
        cursor: pointer;
      }
      .stateA {
        border: 1px solid #00ccff;
      }
      img {
        width: 14px;
        height: 14px;
        margin-right: 0px;
        cursor: pointer;
      }
    }
    .state-active {
      width: 244px;
      height: 122px;
      background: rgba(0, 13, 35, 0.76);
      box-shadow: 0px 0px 6px 1px rgba(0, 204, 255, 0.77),
        inset 0px 0px 14px 1px #00ccff;
      border-radius: 4px 4px 4px 4px;
      border: 1px solid #2c96cd;
      padding: 9px 5px;
      .state {
        width: 80px;
        height: 80px;
        background: #ffffff;
        border-radius: 10px 10px 10px 10px;
        border: 1px solid #707070;
      }
      .stateA {
        border: 1px solid #00ccff;
      }
    }
  }
  .position-wrap {
    position: absolute;
    bottom: 6px;
    right: 17px;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    .position {
      display: flex;
      align-items: center;
      font-size: 14px;

      p {
        // width: 150px;
        margin-right: 10px;
        color: #ffffff;
      }
    }
    .size {
      width: 80px;
      height: 30px;
      background: rgba(0, 17, 46, 0.66);
      box-shadow: 0px 0px 10px 1px rgba(0, 0, 0, 0.47);
      border-radius: 15px 15px 15px 15px;
      border: 1px solid rgba(255, 255, 255, 0.23);
      font-size: 12px;
      color: #ffffff;
      line-height: 1.5;
      text-align: center;
    }
  }
}
</style>
